home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
-
- # (c) Copyright 1992 by Panagiotis Tsirigotis
- # All rights reserved. The file named COPYRIGHT specifies the terms
- # and conditions for redistribution.
-
-
- #
- # $Id: tester,v 7.1 1992/06/01 21:38:57 panos Exp $
- #
-
- #
- # Usage:
- # tester function-name function-name ...
- # or
- # tester all
- #
- # function-name is that name of a sio function (or macro)
- #
-
- copy_file=/usr/dict/words
- temp_file=/tmp/w
- make_log=MAKE.LOG
-
- trap_function()
- {
- rm -f $temp_file $make_log
- echo
- exit 1
- }
-
-
- make_program()
- {
- target=$1
- cflags="$2"
- if test -f $1 -a ! -x $1 ; then rm -f $1 ; fi
- if test "$cflags"
- then
- make -s "$cflags" $target >$make_log 2>&1
- else
- make -s $target >$make_log 2>&1
- fi
- exit_code=$?
- if test $exit_code -eq 0 -a -x $1
- then
- rm -f $make_log
- else
- echo "FAILED"
- echo " The make failed. Check the make log file << $make_log >>"
- exit
- fi
- }
-
-
-
- #
- # test_function expects a single argument, the name of the function
- # it will test.
- # It creates a program that has the name of the function by invoking
- # make with the symbol -DTEST_<function_name>
- # Before it invokes make, it checks if there is a file with the
- # function name, and if it exists and it is not executable, it
- # removes it. The reason is that the SunOS ld will create a target
- # file with the x bit not set if the linking fails.
- #
- test_function()
- {
- expression="echo $"$1
- var=`eval $expression`
- if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
-
- echo -n "TESTING $1 "
- make_program $1 "CFLAGS=-g -DTEST_$1"
-
- ./$1 < $copy_file >$temp_file
- exit_code=$?
- if test $exit_code -ne 0
- then
- echo "FAILED"
- echo " Test program exited with exit code $exit_code"
- echo " Temporary file << $temp_file >> not deleted"
- exit
- fi
- cmp -s $copy_file $temp_file
- if test $? -ne 0
- then
- echo "FAILED"
- echo " The files << $copy_file >> and << $temp_file >> are not the same"
- exit
- else
- echo PASSED
- fi
- rm -f $temp_file
- }
-
-
- test_sprint()
- {
- var=$Sprint
- program=Sprint
- if test "$var" = "no" -o "$var" = "" -a "$all" = "no" ; then return ; fi
-
- echo TESTING Sprint
- if test -f $program -a ! -x $program ; then rm -f $program ; fi
- make_program $program ""
- $TESTSHELL sprint_test
- }
-
-
- trap trap_function 1 2 3 15
-
- #
- # There is a variable for every function to be tester. That variable
- # can have the values "yes" or "".
- # When a function is specified, it takes the value of $run. Initially $run
- # is "yes", so a specified function has its variable set to "yes".
- # If "all" is specified, $run becomes "no", so subsequently specified
- # functions, have their variables set to "no".
- #
- # We test a function iff:
- # its variable is "yes" OR its variable is "" and $all is "yes"
- # We don't test a function iff:
- # its variable is "no" OR its variable is "" and $all is "no"
- #
- # Therefore, all functions specified after "all" will NOT be tested.
- #
- run=yes
- all=no
-
- while test $# -gt 0
- do
- case $1 in
- Sputchar) Sputchar=$run ;;
- Sgetchar) Sgetchar=$run ;;
- Srdline) Srdline=$run ;;
- Sfetch) Sfetch=$run ;;
- Sread) Sread=$run ;;
- Swrite) Swrite=$run ;;
- Sgetc) Sgetc=$run ;;
- Sputc) Sputc=$run ;;
- Sflush) Sflush=$run ;;
- Sundo) Sundo=$run ;;
- Sprint) Sprint=$run ;;
- switch) switch=$run ;;
- switch2) switch2=$run ;;
- all) all=yes ; run="no" ;;
- *) echo Bad argument: $1
- esac
- shift
- done
-
- test_function Sgetchar
- test_function Sputchar
- test_function Sread
- test_function Swrite
- test_function Srdline
- test_function Sfetch
- test_function Sgetc
- test_function Sputc
- test_function Sflush
- test_function Sundo
- test_function switch
- test_function switch2
- test_sprint
-
-